<template>
  <div class="header">
    <div class="el-menu">
    </div>
    <search
      @search-params-btn-emits="searchParamsBtnEmits"
      @reset-params-btn-emits="resetParamsBtnEmits"
    />
  </div>

  <el-table
    :data="tableData"
    style="width: 100%"
    :header-cell-style="{ textAlign: 'center' }"
    :cell-style="{ textAlign: 'center' }"
    height="70vh"
  >
    <el-table-column label="物资唯一码" prop="sku"> </el-table-column>
    <el-table-column label="需求物料编码" prop="materialCode"> </el-table-column>
    <el-table-column label="物料描述" prop="materialDesc" ></el-table-column>
    <el-table-column label="大类描述" prop="divisionDesc" ></el-table-column>
    <el-table-column label="中类描述" prop="groupDesc" ></el-table-column>
    <el-table-column label="小类描述" prop="classDesc" ></el-table-column>
    <el-table-column label="需求数量" prop="demandQuantity" ></el-table-column>
    <el-table-column label="单位" prop="unit" ></el-table-column>
    <el-table-column label="概算总价（元）" prop="estimatetotal" ></el-table-column>
    <el-table-column label="项目名称" prop="projectName" ></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-text type="primary" @click="handleEdit(scope.$index, scope.row)" v-if="apiStore.taskStatus != '2'">
          审核结果明细
        </el-text>

      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    style="margin-top: 20px"
    v-model:current-page="taskStore.page.pagenum"
    v-model:page-size="taskStore.page.size"
    background
    layout="total, prev,sizes, pager, next"
    :total="taskStore.page.total"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
  <Dialog ref="dialogRef"></Dialog>
</template>

<script lang="ts" setup>
import useTaskStore from '@/store/task/index'
import useApiStore from '@/store/api/index.js'

import { useRouter,useRoute } from 'vue-router'
import { ref, watch, reactive } from 'vue'
import Search from '@/views/taskDetail/cpns/search.vue'
import Dialog from '@/views/home/cpns/dialog.vue'
const activeIndex = ref('1')
const handleSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const taskStore = useTaskStore()
const apiStore = useApiStore()
// const page = reactive({
//   pagenum: 1,
//   size: 10,
//   total: 40
// })

let tableData = ref([
  // {
  //   id: 'TASK202501202128321',
  //   create_time: '2024-07-23 16:31:35',
  //   update_time: '2024-07-23 16:31:35',
  //   type: '手动上传',
  //   name: ' 20250118.xls'
  // }

])
const dialogRef = ref()
const router = useRouter()


const route = useRoute()


const searchParamsBtnEmits = async (searchParams:any) => {
  const params = {
    pageNum: apiStore.page.pageNum,
    pageSize: apiStore.page.pageSize,
    mainTaskId:route.query.id,
    ...searchParams
  }
  const res = await taskStore.getTaskDetailList(params)
}


watch(
  () => taskStore.taskDetailList,
  (New, Old) => {
    console.log(New,"888")
    tableData.value =  New.subTaskList
    // tableData.value =  Array.from(New)
    // console.log(tableData.value,"888")

    // tableData.value = New.data

    taskStore.page.total = New.total
  },
  { deep: true }
)
//获取仓库列表
const getWarehouse = async () => {
  const res = await taskStore.getTaskDetailList({
    pageNum: taskStore.page.pagenum,
    pageSize: taskStore.page.size,
    mainTaskId:route.query.id
  })
}
getWarehouse()

//删除表格元素
// const handleDelete = async (index: number, row: TableData) => {
//   await taskStore.delWarehouseHandler(row.id)
//   await taskStore.getWarehouseAction()
// }

//修改table元素
const handleEdit = (index: number, row: any) => {
  router.push({path: '/main/search/detail/checkRes', query: {rowId: row.id} })
  // router.push({ name: 'checkRes',params: row })
  // router.push({ path: '/main/goods', query: { id: row.id, name: row.name } })

}

//新增table元素
const addBtn = () => {
  dialogRef.value.isNewOrUpdate = true
  dialogRef.value.dialogVisible = true
}

const jumpToGoods = (row) => {
  // router.push({ name: 'goods',params: { id: row.id } })

  // router.push({ name: 'user', params: { userId: '123' }})

  router.push({ path: '/main/goods', query: { id: row.id, name: row.name } })
}

//size大小切换
const handleSizeChange = () => {
  getWarehouse()
}

//当前页切换
const handleCurrentChange = () => {
  getWarehouse()
  // loginStore.getUserListInfoAction(page.value, size.value)
}

</script>

<style scoped lang="scss">
.el-text {
  cursor: pointer;
}
.el-menu {
  // margin: 20px 0;
  // padding-bottom: 20px;
  margin-bottom: 20px;
  width: 100%;
  .el-menu--horizontal.el-menu {
    border:none
  }
}
</style>
